//
//(C) Copyright 2011 HongKong Airline.,Ltd. 
//
/**
 * contactPersonDaoHibernate
 *
 * 项目名称:代购系统
 *
 * @author Mengxiangliang
 *
 * 功能描述:
 * 
 * 历史版本:2013-01-04 v1.0.0 Mengxiangliang  创建:
 * 
 */
package com.gamutsoft.amb.contactperson.dao.impl;

import java.util.List;
import java.util.Map;

import com.gamutsoft.amb.common.bean.QueryExample;
import com.gamutsoft.amb.common.dao.impl.GenericDaoHibernate;
import com.gamutsoft.amb.common.exception.BusinessException;
import com.gamutsoft.amb.contactperson.dao.IContactPersonDao;
import com.gamutsoft.amb.contactperson.model.ContactPerson;

@SuppressWarnings("unchecked")
public class ContactPersonDaoHibernate extends GenericDaoHibernate<ContactPerson, Long> implements IContactPersonDao {
    
     public ContactPersonDaoHibernate() {
		super(ContactPerson.class);

	}
    
    /**
	 * 根据条件查询记录
	 * @author Mengxiangliang
	 * @param  QueryExample
	 * @return List<Map>
	 * @throws BusinessException
	 */
	@Override
	public List<Map> searchContactPersonList(QueryExample qe) throws BusinessException {
	
	    StringBuffer sb = new StringBuffer();
		sb.append("SELECT T.ID,T.FIRST_NAME,T.LAST_NAME,T.ADDRESS,T.TELEPHONE,T.EMAIL,T.POST,T.CREATE_TIME,T.USER_ID,T.PACKAGE_ID FROM CONTACT_PERSON T");
		//qe.addOrderBy("");
		return this.findByQueryExample(sb.toString(), qe);
		
	}

	/**
	 * 根据ID查询记录
	 * @author Mengxiangliang
	 * @param id
	 * @return
	 * @throws BusinessException
	 */
	@Override
	public ContactPerson searchContactPersonById(Long id) throws BusinessException {
	
	  ContactPerson domain = new ContactPerson();
	   String hql = "from ContactPerson where id=?";
	   List<ContactPerson> list = this.getHibernateTemplate().find(hql, id);
	   if(list != null && list.size() >0){
		  domain = list.get(0);
	   }
	   return domain;
		
	}

	/**
	 * 删除记录
	 * @author Mengxiangliang
	 * @param id
	 * @throws BusinessException
	 */
	@Override
	public void deleteContactPersonById(Long id) throws BusinessException {
	
	 String hql ="delete from ContactPerson where id=?";
	 this.getHibernateTemplate().bulkUpdate(hql, id);
	 
	}
	
}